﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace PLM.ConfigurationCenter.Core.Expansion {

    public static partial class DataExpansion {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsEmpty(this string val) {
            return string.IsNullOrWhiteSpace(val);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string ToJson<T>(this T val) where T : class, new() {
            return JsonSerializer.Serialize(val);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static int ToIntOrNull(this string val) {
            var res = int.TryParse(val, out int data);
            if (res) {
                return data;
            }
            return 0;
        }
    }
   
}
